#!/bin/bash
########################################################################
####  Script Name: sm-lib-package-install
####  version: 3.4.32
####  Date: 2015-05-28

####  Copyright (C) Harald Hope 2005-2015
####  This program is free software; you can redistribute it and/or modify it under
####  the terms of the GNU General Public License as published by the Free Software 
####  Foundation; either version 2 of the License, or (at your option) any later version.

####  This program is distributed in the hope that it will be useful, but WITHOUT
####  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
####  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

####  Get the full text of the GPL here:
####  http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

####  Script Author: Harald Hope
####  This is a library file for smxi and cannot be run independently

####  Script URL: http://smxi.org/sm/sm-lib-package-install
####  Script SVN: http://code.google.com/p/smxi
####  Script Home page: http://techpatterns.com/forums/about736.html
########################################################################

DEFAULT_DM=''

########################################################################
####  FUNCTIONS
########################################################################

###---------------------------------------------------------------------
### utilities
###---------------------------------------------------------------------
# installs requested packages, 3 args: $1 type; $2 package; $3 optional for pre install
# procedures, full commands that is.
# installer also handles metapackage assignments

package_group_installer()
{
	eval $LOGUS
	local itemName=$2 packageName='' package='' packages=''
	# select: default system/user set/wdm as default if nothing else, if kde, use kdm
	# unless other default override is set
	local dmUse=$( assign_display_manager $itemName )
	local inxiDepends='coreutils gawk grep hostname pciutils procps'
	local inxiXorg='mesa-utils x11-utils x11-xserver-utils'
	local inxiRecommends='dmidecode file hddtemp iproute lm-sensors module-init-tools usbutils'
	local pdfLight='epdfview' mlocate='mlocate' kioapt='kio-apt' kpdf='kpdf'
	local karm='karm' ksvg='ksvg' katePlugins='kate-plugins' kpower='kpowersave'
	local kmoon='kmoon' kickerApplets='kicker-applets' kdeAddonsKfile='kdeaddons-kfile-plugins'
	local kdeMultimediaKfile='kdemultimedia-kfile-plugins'
	local kdeBase='kdebase kdebase-kio-plugins kde-core kdelibs virtuoso-minimal'
	local khelp='khelpcenter' kcolor='kcoloredit' plasmaWidgets=''
	local qt4Config=''
	local lxdeLMC='libmenu-cache0' lxdeMD='lxmenu-data' lxdeSE='lxsession-edit'
	local lxdeIP='lxinput' lxdeM='lxmusic'
	
	# note: these packages are not in every Debian level
	if [ -z "$( check_package_status 'epdfview' )" ];then
		pdfLight='xpdf'
	fi
	if [ -z "$( check_package_status "$mlocate" )" ];then
		mlocate=''
	fi
	if [ "$2" == 'ms-core-fonts' ];then
		if [ -n "$( check_package_status 'ttf-mscorefonts-installer' 'c' )" ];then
			itemName='ttf-mscorefonts-installer'
		elif [ -n "$( check_package_status 'msttcorefonts' 'c' )" ];then
			itemName='msttcorefonts'
		else
			itemName='NA'
		fi
	fi
	# handle incoming changes to kde as well
	if [ -n "$( grep -i 'kde' <<< $2 )" ];then
		if [ "$dmUse" == 'kdm' ];then
			dmUse=''
		fi
		if [ -n "$( check_package_status 'kde-plasma-desktop' )" ];then
			karm='ktimetracker'
			katePlugins=''
			kcolor='kcolorchooser'
			kdeAddonsKfile=''
			kdeBase='kde-plasma-desktop kaboom upower udisks polkit-kde-1'
			kdeMultimediaKfile=''
			khelp='khelpcenter4'
			kickerApplets=''
			kioapt=''
			kmoon=''
			kpdf='okular okular-extra-backends'
			kpower=''
			ksvg=''
			plasmaWidgets='plasma-widgets-addons plasma-widgets-workspace'
			qt4Config='qt4-qtconfig'
		fi
	fi
	if [ -n "$( grep -i 'lxde' <<< $2 )" ];then
		if [ -z "$( check_package_status $lxdeSE )" ];then
			lxdeLMC=''
			lxdeMD=''
			lxdeSE=''
			lxdeIP=''
			lxdeM=''
		fi
	fi
	# set these to null to avoid installing the desktop gunk unless needed
	if [ "$dmUse" == 'kdm' -a -n "$( check_package_status 'kdm' 'i' )" ];then
		dmUse=''
	elif [ "$dmUse" == 'gdm' ];then
		if [ -n "$( check_package_status 'gdm' 'i' )" -o -n "$( check_package_status 'gdm3' 'i' )" ];then
			dmUse=''
		elif [ -n "$( check_package_status 'gdm3' 'c' )" ];then
			dmUse='gdm3'
		fi
	fi

	# package groups, console stuff first so it's included in following
	# apache/php/mysql
	local apache2Main='apache2-mpm-prefork apache2-utils'
	local apache2ModPerl='libapache2-mod-perl2'
	local apache2ModPhp5='libapache2-mod-php5'
	local apache2ModPython='libapache2-mod-python'
	local apache2ModRuby='libapache2-mod-ruby'
	local apacheRapache='rapache'
	local mysql5Client='' # set these below
	local mysql5Server=''
	local mysqlTop='mytop mtop'
	local php5Modules='php5-curl php5-gd'
	local php5Mysql='php5-mysql'
	local php5Postgre='php5-pgsql'
	# handle different distro mysql package availability
	if [ "$2" == 'mysql5-server' ];then
		if [ -n "$( check_package_status 'mysql-server-5.7' 'c' )" ];then
			mysql5Server='mysql-server-5.7'
		elif [ -n "$( check_package_status 'mysql-server-5.6' 'c' )" ];then
			mysql5Server='mysql-server-5.6'
		elif [ -n "$( check_package_status 'mysql-server-5.5' 'c' )" ];then
			mysql5Server='mysql-server-5.5'
		elif [ -n "$( check_package_status 'mysql-server-5.4' 'c' )" ];then
			mysql5Server='mysql-server-5.4'
		elif [ -n "$( check_package_status 'mysql-server-5.3' 'c' )" ];then
			mysql5Server='mysql-server-5.3'
		elif [ -n "$( check_package_status 'mysql-server-5.2' 'c' )" ];then
			mysql5Server='mysql-server-5.2'
		elif [ -n "$( check_package_status 'mysql-server-5.1' 'c' )" ];then
			mysql5Server='mysql-server-5.1'
		elif [ -n "$( check_package_status 'mysql-server-5.0' 'c' )" ];then
			mysql5Server='mysql-server-5.0'
		else # just put in metapackage
			mysql5Server='mysql-server'
		fi
	fi
	if [ "$2" == 'mysql5-client' ];then
		if [ -n "$( check_package_status 'mysql-client-5.7' 'c' )" ];then
			mysql5Client='mysql-client-5.7'
		elif [ -n "$( check_package_status 'mysql-client-5.6' 'c' )" ];then
			mysql5Client='mysql-client-5.6'
		elif [ -n "$( check_package_status 'mysql-client-5.5' 'c' )" ];then
			mysql5Client='mysql-client-5.5'
		elif [ -n "$( check_package_status 'mysql-client-5.4' 'c' )" ];then
			mysql5Client='mysql-client-5.4'
		elif [ -n "$( check_package_status 'mysql-client-5.3' 'c' )" ];then
			mysql5Client='mysql-client-5.3'
		elif [ -n "$( check_package_status 'mysql-client-5.2' 'c' )" ];then
			mysql5Client='mysql-client-5.2'
		elif [ -n "$( check_package_status 'mysql-client-5.1' 'c' )" ];then
			mysql5Client='mysql-client-5.1'
		elif [ -n "$( check_package_status 'mysql-client-5.0' 'c' )" ];then
			mysql5Client='mysql-client-5.0'
		else # just put in metapackage
			mysql5Client='mysql-client'
		fi
	fi

	# server/client packages/groups
	local aTop='' iceDove='icedove' rdiff='rdiff-backup'
	local alsaGroup='alsa-base alsa-utils'

	if [ "$SERVER_CLIENT" == 'server' ];then
		alsaGroup=''
		aTop='atop'
		iceDove=''
		rdiff=''
	fi

	# standard groups
	local sysvRcConf='sysv-rc-conf'
	# starting upstart/systemd checks
	if [ "$B_SYSTEMD" == 'true' ];then
		sysvRcConf=''
	fi
	
	local consoleBrowsers='lynx links elinks links2 w3m' 
	local consoleTools="$aTop bc bzip2 ed htop irssi less nano gzip findutils mc $mlocate iproute p7zip-full p7zip-rar rcconf screen sysstat $sysvRcConf xz-utils zip unzip"
	local baseLightPackages="$consoleBrowsers $consoleTools aterm gpicview leafpad mc pcmanfm sudo vim xarchiver xchat xchat-common xterm $pdfLight"
	local ceniStuff="ifupdown libcurses-perl libcurses-ui-perl libexpect-perl  libterm-readkey-perl udev wireless-tools wpasupplicant"
	local fluxPackages="fluxbox fluxconf"
	local fvwmCrystal="audacious audacious-plugins cdcd debhelper dpatch docbook-xsl fvwm fvwm-crystal fvwm-icons imagemagick mpd python python-support quodlibet rxvt-unicode rox-filer trayer xscreensaver"
	local gnomeExtras="gnome-backgrounds gnome-extra-icons gnome-system-monitor gnome-netstatus-applet"
	local gnomePackages="gnome-core"
	if [ -n "$( grep -i 'gnome' <<< $2 )" ];then
		if [ -n "$( check_package_status 'gnome-sytem-tools' 'c' )" ];then
			gnomePackages="$gnomePackages gnome-sytem-tools"
		fi
	fi
	local googleEarth='googleearth-package'
	local kdeExtras="ark $karm $katePlugins $kcolor $kdeAddonsKfile $kdeMultimediaKfile kdemultimedia-kio-plugins $khelp $kickerApplets $kioapt kmenuedit kmix $kmoon knemo konq-plugins $kpower ksensors ksnapshot kuser $plasmaWidgets $qt4Config pulseaudio puvcontrol"
	local kdePackages="$kdeBase konqueror konversation $kpdf $ksvg $dmUse kdm"
	local kdepimPackages="akregator kmail $karm kontact korganizer kalarm"
	local kofficePackages='koffice '
	local lightOfficePackages="$pdfLight abiword abiword-plugins gnumeric gnumeric-plugins-extra"
	local lxdePackages="$lxdeLMC lxappearance lxappearance-obconf lxde-core lxde-settings-daemon $lxdeMD lxrandr $lxdeSE lxterminal"
	local lxdeExtras="$lxdeIP lxlauncher $lxdeM lxnm"
	local mozillaGroup="$iceDove iceweasel"
	local openboxPackages="openbox obconf obmenu openbox-themes"
	local rsyncGroup="rsync $rdiff"
	local streamTuner='streamtuner2 streamripper'
	local systemUtils="$alsaGroup acpid acpi-support anacron cpufrequtils dbus dbus-X11 gpm hal hddtemp hdparm lm-sensors lsb-core lsb-release iproute pmount powersaved sdparm udev"
	# xfwm4 xfconf  xfce4-panel thunar xfce4-utils gtk2-engines-xfce xfce4-session
	# bad:  xfce4-session xfce4-settings
	local xfcePackages="gtk2-engines-xfce thunar-archive-plugin thunar-media-tags-plugin thunar-thumbnailers thunar-volman xfwm4 xfconf  xfce4-panel thunar xfce4-session xfce4-settings xfce4-utils xfce4-terminal xfdesktop4 xfmedia xfce4-notify tango-icon-theme xfce4-mixer xfce4-volumed"
	local xorgPackages='libgl1-mesa-dri libglu1-mesa libxfont1 libgl1-mesa-glx mesa-utils  xbase-clients xkb-data xfonts-base xfonts-100dpi xfonts-75dpi xfonts-scalable xserver-xorg xserver-xorg-input-all xserver-xorg-video-all xterm xutils'

	echo $LINE
	echo "${S}Installing ${C}$itemName${S}...${N}"
	# transfer meta packages to package installer variable
	case $itemName in
		## apache2/php/mysql
		apache2-configuration)
			packageName="$apacheRapache"
			;;
		apache2-server)
			packageName="$apache2Main"
			;;
		apache2-mod-perl)
			packageName="$apache2ModPerl"
			;;
		apache2-mod-php5)
			packageName="$apache2ModPhp5"
			;;
		apache2-mod-python)
			packageName="$apache2ModPython"
			;;
		apache2-mod-ruby)
			packageName="$apache2ModRuby"
			;;
		mysql5-client)
			packageName="$mysql5Client"
			;;
		mysql5-server)
			packageName="$mysql5Server"
			;;
		mysql-top)
			packageName="$mysqlTop"
			;;
		php5-modules)
			packageName="$php5Modules"
			;;
		php5-mysql)
			packageName="$php5Mysql"
			;;
		php5-postgre)
			packageName="$php5Postgre"
			;;
		## main packages
		base-light-packages)
			packageName="$baseLightPackages"
			;;
		ceni-stuff)
			packageName="$ceniStuff"
			;;
		console-browsers)
			packageName="$consoleBrowsers"
			;;
		console-tools)
			packageName="$consoleTools"
			;;
		fluxbox)
			packageName="$fluxPackages $dmUse"
			;;
		base-plus-fluxbox)
			packageName="$fluxPackages $xorgPackages $dmUse"
			;;
		fvwm-crystal)
			packageName="$fvwmCrystal $dmUse"
			;;
		base-plus-fvwm-crystal)
			packageName="$fvwmCrystal $xorgPackages $dmUse"
			;;
		gnome)
			packageName="$gnomePackages $dmUse"
			;;
		base-plus-gnome)
			packageName="$gnomePackages $xorgPackages $dmUse"
			;;
		gnome-extras)
			packageName="$gnomeExtras"
			;;
		inxi-depends)
			packageName="$inxiDepends"
			;;
		inxi-recommends)
			packageName="$inxiRecommends"
			;;
		inxi-xorg)
			packageName="$inxiXorg"
			;;
		kde)
			packageName="$kdePackages $dmUse"
			;;
		base-plus-kde)
			packageName="$kdePackages $xorgPackages $dmUse"
			;;
		kde-extras)
			packageName="$kdeExtras"
			;;
		kde-pim)
			packageName="$kdepimPackages"
			;;
		koffice)
			packageName="$kofficePackages"
			;;
		light-office)
			packageName="$lightOfficePackages"
			;;
		lxde)
			packageName="$lxdePackages $dmUse"
			;;
		base-plus-lxde)
			packageName="$lxdePackages $xorgPackages $dmUse"
			;;
		lxde-extras)
			packageName="$lxdeExtras"
			;;
		mozilla-group)
			packageName="$mozillaGroup"
			;;
		openbox)
			packageName="$openboxPackages"
			;;
		rsync-group)
			packageName="$rsyncGroup"
			;;
		streamtuner)
			packageName="$streamTuner"
			;;
		system-utilities)
			packageName="$systemUtils"
			;;
		xfce)
			packageName="$xfcePackages $dmUse"
			;;
		base-plus-xfce)
			packageName="$xfcePackages $xorgPackages $dmUse"
			;;
		xorg)
			packageName="$xorgPackages $dmUse"
			;;
		google-earth)
			packageName="$googleEarth"
			;;
		# default: just install the package of $2 directly
		*)
			packageName=$itemName
			;;
	esac
	
	if [ "$packageName" != 'NA' ];then
		if [ -n "$3" ];then
			eval $3 # this removes stuff, or does other operations, first
		fi
		update_sources $1
		# now to make sure no missing packages are attempted, we'll check
		# and only install ones in user system apt. This also future proofs and
		# avoids install errors.
		log_function_data "Raw packageName list to install:\n$packageName"
		echo $LINE
		echo "${S}Checking install package list for availability now...${N}"
		for package in $packageName
		do
			if [ -n "$( check_package_status $package 'c' )" ];then
				echo "${S}Adding ${C}$package${S} to install group.${N}"
				packages="$packages$package "
			else
				echo "${M}Sorry, ${C}$package${M} is not available in ${C}Debian $SYSTEM_BASE${M}!${N}"
			fi
		done
		log_function_data "Tested package list to install:\n$packages"
		if [ -n "$packages" ];then
			package_installer "$packages" 'install-user-ok'
		else
			echo "${E}Sorry, no packages from your requested group: ${C}$itemName${E} are available for installation.${N}"
		fi
	else
		echo "${E}Sorry, no packages from your requested group: ${C}$2${E} are available for installation.${N}"
	fi
	eval $LOGUE
}

# args: $1 packages to be installed
set_server_client()
{
	eval $LOGUS
	local opt='' options='' repeat='' defaultString='default client setting'

	if [ -n "$SERVER_CLIENT" ];then
		defaultString="your current selection: ${C}$SERVER_CLIENT${S}"
	fi
	echo $MLINE
	echo "${M}System Type Selector"
	echo $MLINE
	echo "${S}Please select which system type you are installing. Your choice will"
	echo "determine some package group items in ${C}Package Install${S}."
	echo
	echo "You can change this setting any time by just returning to the main"
	echo "package install menu and picking this option again."
	echo $MLINE
	echo "${C}1 - client${S} Default, everything included."
	echo "${C}2 - server${S} Skips Alsa, Thunderbird, rsync-backup if you install those groups."
	echo "${C}3 - skip-return-to-menu${S} Leave things alone, use $defaultString."
	echo $LINE
	echo -e $SLE
	echo $LINE
	options="client server skip-return-to-menu"
	select opt in $options
	do
		log_function_data "opt selected: $opt"
		case $opt in
			client|server)
				echo "${S}Package install is now set to use: ${C}$opt${N}"
				SERVER_CLIENT=$opt
				;;
			skip-return-to-menu)
				echo "${S}Ok, using $defaultString - not changing anything.${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done

	eval $LOGUE
	if [ "$repeat" == 'true' ];then
		set_server_client
	fi
}

###---------------------------------------------------------------------
### main package install group selectors
###---------------------------------------------------------------------

# main selector, pick which package group type to install
select_install_type()
{
	eval $LOGMS
	local repeat='' options='' opt=''
	local officeString='LibreOffice'
	
	if [ "$OFFICE_AVAILABLE" == 'ooo' ];then
		officeString='OpenOffice.org'
	fi

	print_lib_info $LIB_PACKAGE_INSTALL
	echo $MLINE
	echo "${S}The following sections will be expanded over time, but these are your "
	echo "current Package Install options (apt sources updated where needed):"
	if [ -n "$SERVER_CLIENT" ];then
		echo
		echo "${M}You are using the following install type: ${C}$SERVER_CLIENT"
	fi
	echo $LINE
	echo "${C}1${S} - ${C}office${S} Features $officeString installer. Language pack selector."
	echo "    Now also offers $officeString hold/install/update option as well."
	echo
	echo "${C}2${S} - ${C}non-free${S} Flash plugin, Java plugin, MS core fonts, Opera, Skype, Google Earth, Google Chrome (with Flash)."
	echo
	echo "${C}3${S} - ${C}utilities${S} tools: console browsers, networking (ceni), swiftfox, inxi, and more."
	echo
	echo "${C}4${S} - ${C}desktop-environment${S} Install Xorg, Gnome, Kde, Xfce, fVwm Crystal, Lxde."
	echo
	echo "${C}5${S} - ${C}servers${S} Install Samba, NFS, and Apache2 (+MySql,PHP) server components."
	echo
	echo "${C}6${S} - ${C}select-system-type${S} Set client/server system type flag. This will remove"
	echo "    or add a few items from package groups depending on your selection. Most people"
	echo "    can skip this, but if you're setting up a server, you might want to set this flag."
	echo
	echo "${C}7${S} - ${C}back-to-main-menu${S}"

	echo $LINE
	echo -e $SLE
	echo $LINE

	options="office non-free utilities desktop-environment servers select-system-type back-to-main-menu"
	select opt in $options
	do
		case $opt in
			office)
				office_installer
				repeat='true'
				;;
			non-free)
				non_free_installer
				repeat='true'
				;;
			utilities)
				utilities_installer
				repeat='true'
				;;
			desktop-environment)
				desktop_environment_installer
				repeat='true'
				;;
			servers)
				server_group_selector
				repeat='true'
				;;
			select-system-type)
				set_server_client
				repeat='true'
				;;
			back-to-main-menu)
				echo "${S}Thanks for checking out the Package Installer.${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done
	eval $LOGME
	if [ "$repeat" == 'true' ];then
		select_install_type
	fi
}

# install office suites, languages packs, etc
office_installer()
{
	eval $LOGPS
	local repeat='' options='' opt=''
	local officeString='LibreOffice' officeOpt='libreoffice'
	local installedOfficeString='LibreOffice' installedOfficeOpt='libreoffice'
	
	if [ "$OFFICE_AVAILABLE" == 'ooo' ];then
		officeString='OpenOffice.org'
		officeOpt='openoffice.org'
	fi
	if [ "$OFFICE_INSTALLED" == 'ooo' ] || [ "$OFFICE_AVAILABLE" == 'ooo' -a -z "$OFFICE_INSTALLED" ];then
		installedOfficeString='OpenOffice.org'
		installedOfficeOpt='openoffice.org'
	fi

	echo $MLINE
	echo "${M} Office Installer"
	echo $MLINE
	echo "${S}Pick which free office suite you would like to install:"
	echo $LINE
	echo "${C}1${S} - ${C}$officeOpt${S} Installs all components of $officeString, and also lets"
	echo "    You choose your $officeString language packs and dictionaries, when available."
	echo "${C}2${S} - ${C}$installedOfficeOpt-hold-install${S} Change dpkg install status to ${C}hold/install${S}, or update to"
	echo "    latest if ${C}$installedOfficeString${S} is already installed."
	echo
	echo "${C}3${S} - ${C}koffice${S} Installs the main koffice components."
	echo "${C}4${S} - ${C}kde-pim${S} Installs the kpim components. That's personal information"
	echo "    manager stuff: ${C}kdepim karm kontact korganizer kalarm"
	echo
	echo "${C}5${S} - ${C}light-office${S} gtk based lightweight office tools: abiword, gnumeric, extras"
	echo
	echo "${C}6${S} - ${C}back-to-install-menu${S}"

	echo $LINE
	echo -e $SLE
	echo $LINE

	options="$officeOpt $installedOfficeOpt-hold-install koffice kde-pim light-office back-to-install-menu"
	select opt in $options
	do
		case $opt in
			$officeOpt)
				update_sources plain
				install_libre_open_office
				repeat='true'
				;;
			$installedOfficeOpt-hold-install)
				run_script_import $LIB_MISC_TWEAKS
				open_libre_office_hold_install
				repeat='true'
				;;
			koffice)
				package_group_installer plain koffice
				repeat='true'
				;;
			kde-pim)
				package_group_installer plain kde-pim
				repeat='true'
				;;
			light-office)
				package_group_installer plain light-office
				repeat='true'
				;;
			back-to-install-menu)
				: # echo "${S}Thanks for checking out the Package Installer.${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done
	eval $LOGPE
	if [ "$repeat" == 'true' ];then
		office_installer
	fi
}

# main selector, pick which package group type to install
non_free_installer()
{
	eval $LOGPS
	local repeat='' options='' opt='' gge64=''
	if [ "$BITS" == "64" ];then
		# gge64="\n${C}googleearth${M} install is not currently supported for ${C}64 bit${M}, sorry."
		:
	fi

	echo $MLINE
	echo "${M} Non Free Software Installer"
	echo $MLINE
	echo "${S}Non-free software options. Check out the Free versions too.:"
	echo $LINE
	echo "${C}1${S} - ${C}Opera${S} One of the better Non Free packages here. Web browser."
	echo "    Will add opera.com sources to your ${C}$EAS${S}."
	echo "${C}2${S} - ${C}update-opera-keyrings${S} Update to latest keyrings from Opera."
	echo "${C}3${S} - ${C}Google Chrome (stable)${S} Stable, ie, long term release, version of Chrome. Web browser."
	echo "    Will add google.com sources to your ${C}$EAS${S}. Includes current Flash player built in."
	echo "    Note: this is the official Google release, with its phone home features."
	echo "${C}4${S} - ${C}Google Chrome (unstable)${S} Unstable, ie, latest, version of Chrome. Web browser."
	echo "    Will add google.com sources to your ${C}$EAS${S}. Includes current Flash player built in."
	echo "    Note: this is the official Google release, with its phone home features."
	echo "${C}5${S} - ${C}update-chrome-keyrings${S} Update to latest keyrings from Google Chrome."
	echo "${C}6${S} - ${C}flash${S} Installs the flash plugin, for use by all browsers."
	echo "    Check out the new FSF gnash player for the Free Software version flash player."
	echo "${C}7${S} - ${C}java-plugin${S} Installs the Java plugin and jre, for use by all browsers."
	echo "    Depending on your system, this will either be the ${C}Oracle/Sun${S} version or ${C}icedtea-plugin${S}"
	echo "${C}8${S} - ${C}ms-core-fonts${S} Installs the basic set of Microsoft TrueType fonts, arial, times new roman, etc."
	echo "${C}9${S} - ${C}skype${S} Installs Skype. Hate it or love it, here it is."
	echo -e "${C}10${S} - ${C}google-earth${S} Installs google earth using Debian installer method.$gge64"
	echo "    ${M}NOTE: This is working again in at least Debian Sid, installs latest and it starts."
	echo
	echo "${C}11${S} - ${C}back-to-install-menu${S}"

	echo $LINE
	echo -e $SLE
	echo $LINE

	options="opera update-opera-keyrings google-chrome-stable google-chrome-unstable update-chrome-keyrings flash-plugin java-plugin ms-core-fonts skype google-earth back-to-install-menu"
	select opt in $options
	do
		case $opt in
			opera)
				# sources update is called in following function
				package_group_installer opera opera
				repeat='true'
				;;
			update-opera-keyrings)
				echo "${S}Updating Opera keyrings..."${N}
				wget -O - http://deb.opera.com/archive.key | apt-key add -
				repeat='true'
				;;
			flash-plugin)
				# first we  need to make sure that user system has non-free
				update_to_nonfree_sources
				# then test for sid version of flash
				if [ -n "$( check_package_status 'flashplugin-nonfree' )" ];then
					package_group_installer 'plain' 'flashplugin-nonfree'
				elif [ -n "$( check_package_status 'flashplayer-mozilla' )" ];then
					package_group_installer 'plain' 'flashplayer-mozilla'
				else
					error_handler 'package-unavailable' $FUNCNAME 'flashplugin-nonfree/flashplayer-mozilla'
				fi
				repeat='true'
				;;
			google-chrome-stable)
				package_group_installer 'google-chrome' 'google-chrome-stable' 
				;;
			google-chrome-unstable)
				package_group_installer 'google-chrome' 'google-chrome-unstable' 
				;;
			update-chrome-keyrings)
				echo "${S}Updating Google Chrome keyrings..."${N}
				wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
				repeat='true'
				;;
			java-plugin)
				java_plugin_installer
				repeat='true'
				;;
			ms-core-fonts)
				package_group_installer plain ms-core-fonts 'update_to_nonfree_sources'
				repeat='true'
				;;
			skype)
				reinstall_skype
				repeat='true'
				;;
			google-earth)
				install_google_earth
				repeat='true'
				;;
			back-to-install-menu)
				: # echo "${S}Thanks for checking out the Package Installer.${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done
	eval $LOGPE
	if [ "$repeat" == 'true' ];then
		non_free_installer
	fi
}
#katapult (personally) and kshutdown yakuake
# various utilities

# apt: install yakuake  hardinfo lshw
utilities_installer()
{
	eval $LOGPS
	local repeat='' options='' opt=''
	local systemUtils="alsa gpm dbus dbus-X11 hal hdparm hddtemp lm-sensors iproute pmount powersaved sdparm udev"

	if [ "$SERVER_CLIENT" == 'server' ];then
		systemUtils="gpm dbus dbus-X11 hal hdparm hddtemp lm-sensors iproute pmount powersaved sdparm udev"
	fi

	echo $MLINE
	echo "${M} Utilities Installer"
	echo $MLINE
	echo "${S}A small, and to increase, collection of useful utilities you might not know about:"
	echo $LINE
	echo "${C}1${S} - ${C}console-tools${S} Wide range of useful console tools: sysv-rc-conf."
	echo "    (good runlevel editor), sysstat, htop, zip/bzip/gzip/p7zip, irssi (nice irc client)."

	echo "${C}2${S} - ${C}console-browsers${S} Installs a full suite of console browsrs."
	echo "    Check it out, these are small, fast, and really pleasant. See how the non-gui side."
	echo "    Installs: ${C}lynx links elinks links2 w3m${S} (links2 is my favorite)"
	echo "    Hey, everyone has their favorite! See if you find one you like..."


	echo "${C}3${S} - ${C}system-utilities${S} All the basics (plus related packages), and a few nice tools:"
	echo "    ${C}$systemUtils"

	echo "${C}4${S} - ${C}swiftfox${S} Lets you pick from a list of ${C}swiftfox${S} versions that match your cpu type"
	echo "    for optimal performance. Will show your installed cpu so you can make the right choice."

	echo "${C}5${S} - ${C}streamtuner${S} Installs ${C}streamtuner2 and streamripper${S}"
	echo "    These are convient tools to listen to audio streams, and record them."
	echo
	echo "${C}6${S} - ${C}captive-to-ntfs-3g${S} Replaces ${C}Captive${S} with ${C}ntfs-3g${S} for ntfs read/write on linux."
	echo "    Highly recommended if you dual boot with ntfs partitions and want to write to them."

	echo "${C}7${S} - ${C}yakuake${S} Quake style terminal emulator for ${C}kde${S}."

# 	echo "${C}6${S} - ${C}kpowersave${S} Install ${C}kpowersave / powersaved${S}."
# 	echo "    This will also remove completely all ${C}powernowd / apmd${S} components."
	echo "${C}8${S} - ${C}h2-favorites${S} This will setup a machine with all the apps I like to use."
	echo "    Asks before installing each package group, so you can decide for yourself if you want each group."
	#kshutdown - shutdown/reboot timer for kde
	#katapult - alternative way of startings apps
	echo "${C}9${S} - ${C}ceni-sid${S} Install ${C}ceni${S}, a good command line tool to setup wired and wireless networking."
	echo "     Install this version for current ${C}Debian Testing${S} and ${C}Unstable/Sid${S}."
	echo "${C}10${S} - ${C}ceni-stable${S} Installs older version of Ceni for ${C}Debian Stable${S}."
	echo "${C}11${S} - ${C}inxi${S} Install ${C}inxi${S} + all dependencies/recommends. Feature rich CLI sys info tool."
	echo "     If ${C}Konversation${S} is present, also creats link so you can run inxi directly: ${C}/inxi${S}"
	echo "     Runs once with full (${C}-F${S}) options when you install it. See ${C}inxi -h${S} for all options."
	echo "${C}12${S} - ${C}rbxi${S} Download/install ${C}rbxi package${S}, the new rysnc/rdiff-backup tool."
	echo "     ${M}Note:${S} installs to: ${C}$SCRIPT_HOME${S}. Manual configuration required. For setup info, see:"
	echo "     ${C}$SCRIPT_HOME/rbxi-data/rbxi-values${S} and ${C}$SCRIPT_HOME/rbxi-data/readme-rbxi.htm${S}"

# 	echo "    This will also remove completely all ${C}powernowd / apmd${S} components."

	echo
	echo "${C}13${S} - ${C}back-to-install-menu${S}"

	echo $LINE
	echo -e $SLE
	echo $LINE

	options="console-tools  console-browsers system-utilities swiftfox streamtuner captive-to-ntfs-3g yakuake h2-favorites ceni-sid ceni-stable inxi rbxi back-to-install-menu"
	select opt in $options
	do
		case $opt in
			captive-to-ntfs-3g)
				update_sources 'plain'
				install_ntfs_3g
				repeat='true'
				;;
			ceni-sid)
				# package_group_installer plain ceni-stuff
				install_ceni 'sid'
				repeat='true'
				;;
			ceni-stable)
				# package_group_installer plain ceni-stuff
				install_ceni 'stable'
				repeat='true'
				;;
			console-tools)
				package_group_installer 'plain' 'console-tools'
				repeat='true'
				;;
			console-browsers)
				package_group_installer 'plain' 'console-browsers'
				repeat='true'
				;;
			h2-favorites)
				h2_faves
				repeat='true'
				;;
			inxi)
				inxi_installer
				repeat='true'
				;;
			kpowersave)
				update_sources 'plain'
				install_kpowersave
				repeat='true'
				;;
			rbxi)
				package_group_installer 'plain' 'bzip2 rsync'
				update_all_scripts 'rbxi' 'internal'
				repeat='true'
				;;
			streamtuner)
				package_group_installer 'plain' 'streamtuner'
				repeat='true'
				;;
			swiftfox)
				swiftfox_installer
				repeat='true'
				;;
			system-utilities)
				package_group_installer 'plain' 'system-utilities'
				repeat='true'
				;;
			yakuake)
				package_group_installer 'plain' 'yakuake'
				repeat='true'
				;;
			back-to-install-menu)
				: # echo "${S}Thanks for checking out the Package Installer.${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done
	eval $LOGPE
	if [ "$repeat" == 'true' ];then
		utilities_installer
	fi
}

desktop_environment_installer()
{
	eval $LOGPS
	local displayManager=$( get_default_display_manager )
	local repeat='' options='' opt=''
	local xorgPackages=''

	if [ -z "$displayManager" ];then
		displayManager='none detected'
	fi

	echo $MLINE
	echo "${M} Desktop Environment Installer"
	echo $MLINE
	echo "${S}Get started if you're building this from nothing at all, or just add some extras."
	echo "${M}Recommendation:${S} if you are starting from no desktop installed, use the ${C}full${S} option."
	echo "If you have ${C}xorg${S} already installed, then the standard is probably fine."
	echo
	if [ -z "$DEFAULT_DM" ];then
		echo "Note: Use option ${C}1${S} first if you have a preference and have no display manager installed."
		echo "If you do not run ${C}1${S} prior to creating your desktop, it will default to use ${C}wdm${S} if you"
		echo "currently have no display manager. Your current default is: ${C}$displayManager${S}"
		echo "(The display manager is the login screen you see when starting up your desktop)"
		echo
		echo "Note: kde defaults to use ${C}kdm${S} if you have no current default and you have not"
		echo "picked an alternate in ${C}1${S}."
	else
		echo "${S}You have chosen to use this display manager: ${C}$DEFAULT_DM${S}"
	fi

	echo $LINE
	echo "${C}1${S} - ${C}select-display-manager${S} Select an alternate display manager to use"
	echo "${C}2${S} - ${C}base-light-packages${S} Installs basic light apps for light desktops"
	echo "    (xchat, leafpad, pcmanfm, etc). No gtk/qt apps."
	echo "${C}3${S} - ${C}system-utilities${S} Make sure you have it in: hal/udev alsa gpm."
	echo "${C}4${S} - ${C}xorg${S} All the xorg pieces you need to get up and running."
	echo "${C}5${S} - ${C}base-plus-xorg${S} xorg + system-utilities + wdm if kdm/gdm not present."
	echo "${C}6${S} - ${C}fluxbox${S} Installs lightweight window manager.  Good for old hardware."
	echo "${C}7${S} - ${C}base-plus-fluxbox${S} fluxbox + xorg + system utitilies/base light packages + display manager."
	echo "${C}8${S} - ${C}fvwm-crystal${S} Installs lightweight window manager."
	echo "${C}9${S} - ${C}base-plus-fvwm-crystal${S} fvwm-crystal + xorg + system utitilies/base light packages + display manager."
	echo "${C}10${S} - ${C}gnome${S} Base packages for gnome desktop + gnome-applets, konversation, konqueror."
	echo "${C}11${S} - ${C}base-plus-gnome${S} gnome + xorg + system utitilies + gdm (if no dm installed)."
	echo "${C}12${S} - ${C}gnome-extras${S} Installs extras like gnome-backgrounds, gnome-extra-icons, etc."
	echo "${C}13${S} - ${C}kde${S} Base packages for kde desktop + kpdf/okular, konversation, konqueror."
	echo "${C}14${S} - ${C}base-plus-kde${S} kde + xorg + system utitilies + kdm (if no dm installed)."
	echo "${C}15${S} - ${C}kde-extras${S} Installs extras like konq-plugins, color picker, ark, knemo, kmix, etc."
	echo "     This also installs pulseaudio, which is needed for kde sound."
	echo "${C}16${S} - ${C}kde-pim${S} akregator, karm/ktimetracker, kontact, korganizer, kalarm."
	echo "${C}17${S} - ${C}lxde${S} Installs popular new lightweight window manager. Good for old hardware."
	echo "${C}18${S} - ${C}base-plus-lxde${S} lxde + xorg + system utitilies/base light packages + display manager."
	echo "${C}19${S} - ${C}lxde-extras${S} Installs extras like lxnm, lxlauncher, lxmusic, etc (if available)."
	echo "${C}20${S} - ${C}openbox${S} Installs lightweight window manager. Also adds openbox/kde or "
	echo "     openbox/gnome option in gdm/kdm which lets you run a lighter weight version of those desktops."
	echo "${C}21${S} - ${C}xfce${S} A really pleasant, light weight but not light featured display manager. Uses gdm."
	echo "${C}22${S} - ${C}base-plus-xfce${S} xfce + xorg + system utitilies/base light packages + gdm if kdm/gdm not present."
	echo "${C}23${S} - ${C}back-to-install-menu${S}"

	echo $LINE
	echo -e $SLE
	echo $LINE

	options="select-display-manager base-light-packages system-utilities xorg base-plus-xorg fluxbox base-plus-fluxbox fvwm-crystal base-plus-fvwm-crystal gnome base-plus-gnome gnome-extras kde base-plus-kde kde-extras kde-pim lxde base-plus-lxde lxde-extras openbox xfce base-plus-xfce back-to-install-menu"
	select opt in $options
	do
		case $opt in
			base-light-packages)
				package_group_installer 'plain' 'base-light-packages'
				repeat='true'
				;;
			fluxbox)
				package_group_installer 'plain' 'fluxbox'
				repeat='true'
				;;
			base-plus-fluxbox)
				package_group_installer 'plain' 'base-plus-fluxbox'
				package_group_installer 'plain' 'system-utilities'
				package_group_installer 'plain' 'base-light-packages'
				repeat='true'
				;;
			fvwm-crystal)
				package_group_installer 'plain' 'fvwm-crystal'
				repeat='true'
				;;
			base-plus-fvwm-crystal)
				package_group_installer 'plain' 'base-plus-fvwm-crystal'
				package_group_installer 'plain' 'system-utilities'
				package_group_installer 'plain' 'base-light-packages'
				repeat='true'
				;;
			gnome)
				package_group_installer 'plain' 'gnome'
				repeat='true'
				;;
			base-plus-gnome)
				package_group_installer 'plain' 'base-plus-gnome'
				package_group_installer 'plain' 'system-utilities'
				repeat='true'
				;;
			gnome-extras)
				package_group_installer 'plain' 'gnome-extras'
				repeat='true'
				;;
			kde)
				package_group_installer 'plain' 'kde'
				repeat='true'
				;;
			base-plus-kde)
				package_group_installer 'plain' 'base-plus-kde'
				package_group_installer 'plain' 'system-utilities'
				repeat='true'
				;;
			kde-extras)
				package_group_installer 'plain' 'kde-extras'
				repeat='true'
				;;
			kde-pim)
				package_group_installer 'plain' 'kde-pim'
				repeat='true'
				;;
			lxde)
				package_group_installer 'plain' 'lxde'
				repeat='true'
				;;
			base-plus-lxde)
				package_group_installer 'plain' 'base-plus-lxde'
				package_group_installer 'plain' 'system-utilities'
				package_group_installer 'plain' 'base-light-packages'
				repeat='true'
				;;
			lxde-extras)
				package_group_installer 'plain' 'lxde-extras'
				repeat='true'
				;;
			openbox)
				package_group_installer 'plain' 'openbox'
				repeat='true'
				;;
			select-display-manager)
				select_display_manager
				repeat='true'
				;;
			system-utilities)
				package_group_installer 'plain' 'system-utilities'
				repeat='true'
				;;
			xfce)
				package_group_installer 'plain' 'xfce'
				repeat='true'
				;;
			base-plus-xfce)
				package_group_installer 'plain' 'base-plus-xfce'
				package_group_installer 'plain' 'system-utilities'
				package_group_installer 'plain' 'base-light-packages'
				repeat='true'
				;;
			xorg)
				package_group_installer 'plain' 'xorg'
				repeat='true'
				;;
			base-plus-xorg)
				package_group_installer 'plain' 'xorg'
				package_group_installer 'plain' 'system-utilities'
				repeat='true'
				;;
			back-to-install-menu)
				: # echo "${S}Thanks for checking out the Package Installer.${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done
	eval $LOGPE
	if [ "$repeat" == 'true' ];then
		desktop_environment_installer
	fi
}

select_display_manager()
{
	eval $LOGPS
	local displayManager=$( get_default_display_manager )
	local repeat='' options='gdm kdm xdm entrance lightdm nodm slim wdm back-to-desktop-install' opt=''

	echo $MLINE
	echo "${M}Display Manager Selector"
	echo $MLINE
	if [ -z "$displayManager" ];then
		displayManager='none detected'

		echo "Please select from the following list. Note that non gdm/kdm display managers "
		echo "sometimes require extra configurations to allow user shutdown from desktop."
		echo "Your current default is: ${C}$displayManager${S}"
		echo $LINE
		
		echo "${C}1 - gdm${S} Default display / login manager for gnome."
		echo "Will install gdm3 if present, otherwise installs gdm regular."
		echo "${C}2 - kdm${S} Default display / login manager for kde."
		echo "${C}3 - xdm${S} Default display / login manager for X11/xorg (very plain and basic)."
		echo "    For non gnome/kde desktops."
		echo "${C}4 - entrance${S} Alternate display / login manager for non kde/gnome desktops."
		echo "${C}5 - lightdm${S} As name indicates, a light display manager."
		echo "${C}6 - nodm${S} Contrary to name, it is in fact a light display manager."
		
		echo "${C}7 - slim${S} Alternate display / login manager for non kde/gnome desktops."
		echo "    Very light weight, thus the name. Also unreliable, not recommended."
		echo "${C}8 - wdm${S} Alternate display / login manager for non kde/gnome desktops."
		echo $LINE
		echo -e $SLE
		echo $LINE

		select opt in $options
		do
			case $opt in
				gdm|kdm|xdm|entrance|lightdm|nodm|slim|wdm)
					# note: slim is not in every Debian level
					if [ "$opt" == 'gdm' -a -n "$( check_package_status "gdm3" 'c' )" ] || \
					[ -n "$( check_package_status "$opt" 'c' )" ];then
						echo "${S}Your default display manager for your desktop install is now: ${C}$opt${N}"
						DEFAULT_DM=$opt
					else
						echo "${E}The display manager ${C}$opt${E} is not currently in your Debian branch."
						echo "Please select another one.${N}"
						repeat='true'
					fi
					log_function_data "DEFAULT_DM: $DEFAULT_DM"
					print_hec
					;;
				back-to-desktop-install)
					echo "${S}Returning to desktop selections...${N}"
					;;
				*)
					print_error opt
					repeat='true'
					;;
			esac
			break
		done
		eval $LOGPE
		if [ "$repeat" == 'true' ];then
			select_display_manager
		fi
	else
		echo "${S}Your system already has a default display manager: ${C}$displayManager${N}"
		print_hec
		eval $LOGPE
	fi
}

# returns proper dm to use in installer function
# args: $1 - item from package group installer
assign_display_manager()
{
	eval $LOGUS
	local displayManager=$( get_default_display_manager )
	local itemName=$1

	if [ -z "$displayManager" ];then
		# assign the user set one
		if [ -n "$DEFAULT_DM" ];then
			displayManager=$DEFAULT_DM
		else
			case $itemName in
				kde|base-plus-kde)
					displayManager='kdm'
					;;
				gnome|base-plus-gnome|xfce|base-plus-xfce)
					displayManager='gdm'
					;;
				*)
					displayManager='wdm'
					;;
			esac
		fi
	fi
	echo $displayManager
	log_function_data "displayManager: $displayManager"
	eval $LOGUE
}

###---------------------------------------------------------------------
### package install stuff - office suites
###---------------------------------------------------------------------
install_libre_open_office()
{
	eval $LOGPS
	# data is this order: Note that we can offer alternate packs for various packages/langs
	# note: no entry for en-us language pack since that's part of common
	# LanguagePack:Hyphenation:Help:Thesaurus:myspell:<Language Name>
	local officeData='
	af:af:af:af:af:Afrikaans 
	ar:ar:ar:ar:ar:Arabic 
	be-by:be-by:be-by:be-by:be-by:Belarussian 
	bg:bg:bg:bg:bg:Bulgarian 
	bn:bn:bn:bn:bn:Bengali 
	br:br:br:br:br:Breton 
	bs:bs:bs:bs:bs:Bosnian 
	ca:ca:ca:ca:ca:Catalan 
	cs:cs:cs:cs:cs-cz:Czech 
	cy:cy:cy:cy:cy:Welsh 
	da:da:da:da:da:Danish 
	de:de:de:de:de-de:German
	el:el:el:el:el-gr:Greek 
	en-gb:en-gb:en-gb:en-gb:en-gb:English_british 
	en-us:en-us:en-us:en-us:en-us:English_american 
	en-za:en-za:en-za:en-za:en-za:English_southafrican 
	es:es:es:es:es:Spanish 
	et:et:et:et:et:Estonian 
	fa:fa:fa:fa:fa:Farsi 
	fi:fi:fi:fi:fi:Finnish 
	fr:fr:fr:fr:fr:French 
	ga:ga:ga:ga:ga:Gaelic 
	gl:gl:gl:gl:gl:Galician
	gu:gu:gu:gu:gu:Gujarati 
	he:he:he:he:he:Hebrew 
	hi:hi:hi:hi:hi:Hindi 
	hr:hr:hr:hr:hr:Croatian 
	hu:hu:hu:hu:hu:Hungarian 
	it:it:it:it:it:Italian 
	ja:ja:ja:ja:ja:Japanese 
	ka:ka:ka:ka:ka:Georgian 
	km:km:km:km:km:Khmer 
	ko:ko:ko:ko:ko:Korean 
	ku:ku:ku:ku:ku:Kurdish 
	lo:lo:lo:lo:lo:Lao 
	lt:lt:lt:lt:lt:Lithuanian 
	lv:lv:lv:lv:lv:Latvian 
	mk:mk:mk:mk:mk:Macedonian 
	ml:ml:ml:ml:ml:Malayalam 
	nb:nb:nb:nb:nb:Norwegian_bokmaal 
	nn:nn:nn:nn:nn:Norwegian_nynorsk 
	ne:ne:ne:ne:ne:Nepalese 
	nl:nl:nl:nl:nl:Dutch 
	nr:nr:nr:nr:nr:Ndebele 
	pa-in:pa-in:pa-in:pa-in:pa-in:Punjabi 
	pl:pl:pl:pl:pl:Polish 
	pt:pt:pt:pt:pt-pt:Portuguese 
	pt-br:pt-br:pt-br:pt-br:pt-br:Portuguese_brazilian 
	ru:ru:ru:ru:ru:Russian 
	rw:rw:rw:rw:rw:Kinarwanda 
	sk:sk:sk:sk:sk:Slovak 
	sl:sl:sl:sl:sl:Slovenian 
	sr-cs:sr-cs:sr-cs:sr-cs:sr-cs:Serbian 
	st:st:st:st:st:Southern_sotho 
	sv:sv:sv:sv:sv-se:Swedish 
	ta:ta:ta:ta:ta:Tamil 
	te:te:te:te:te:Telugu 
	tg:tg:tg:tg:tg:Tajik 
	th:th:th:th:th:Thai 
	ti-er:ti-er:ti-er:ti-er:ti-er:Tigrinya 
	tn:tn:tn:tn:tn:Tswana 
	tr:tr:tr:tr:tr:Turkish 
	ts:ts:ts:ts:ts:Tsonga 
	vi:vi:vi:vi:vi:Vietnamese 
	xh:xh:xh:xh:xh:Xhosa 
	zh-cn:zh-cn:zh-cn:zh-cn:zh-cn:Chinese_simplified 
	zh-tw:zh-tw:zh-tw:zh-tw:zh-tw:Chinese_traditional 
	zu:zu:zu:zu:zu:Zulu 
	no-change'

	local officeLanguages='' l='' ll='' language='' lang=''
	local officeLang='' officeHyph='' officeHelp='' officeThesaurus='' officeDictionary='' officeDesktop=''
	local doptions='' dopt='' complete='' options=''  opt='' found='' skip=''
	local officePrefix='libreoffice'
	local officeString='LibreOffice'
	local thesaurusPrefix='mythes'
	local hyphenationPrefix='hyphen'
	
	if [ "$OFFICE_AVAILABLE" == 'ooo' ];then
		officePrefix='openoffice.org'
		officeString='OpenOffice.org'
		thesaurusPrefix='openoffice.org-thesaurus'
		hyphenationPrefix='openoffice.org-hyphenation'
	fi
	
	# xxxoffice-gtk conflicts with this package
	if [ -z "$( package_tester 'gtk-qt-engine' )" ];then
		officeDesktop="$officePrefix-gtk"
	fi

	for l in $officeData
	do
		ll=$( echo $l | cut -d ':' -f 6 )
		officeLanguages=$officeLanguages$ll' '
	done

	echo $MLINE
	echo "${M}$officeString Installer"
	echo $MLINE
	echo "${S}You can pick which language information to use with your $officeString install."
	echo "Once you make your selection, all required $officeString components will be installed."
	echo
	echo "When you select one of these your ${C}$officeString${S} install will use"
	echo "any available language specific items for your chosen language, including"
	echo "the language pack, help, thesaurus, and dictionaries."
	if [ -n "$officeDesktop" ];then
		echo "Also installs the desktop integration package: $officeDesktop"
	fi
	echo
	echo "Select the number for ${C}no-change${S} if you want to return to main script."

	echo $LINE
	echo -e $SLE
	echo $LINE

	options=$officeLanguages

	select opt in $options
	do
		for language in $officeData
		do
			if [ "$opt" == "$( echo $language | cut -d ':' -f 6 )" ];then
				found='true'
				if [ "$language" == 'no-change' ];then
					skip='true'
				else
					echo "${S}Checking for packages for ${C}$opt${S} now...${N}"
					
					lang=$( echo $language | cut -d ':' -f 1 )
					officeLang="$officePrefix-l10n-$lang"
					echo -n "  ${C}$officeLang${S} status: "
					if [ "$lang" != '' -a -n "$( check_package_status "$officeLang" 'c' )" ];then
						echo "${M}available${N}"
					else
						echo "${M}no installation candidate${N}"
						officeLang=''
					fi
					
					lang=$( echo $language | cut -d ':' -f 2 ) # not used, causes errors
					officeHyph="$hyphenationPrefix-$lang"
					echo -n "  ${C}$officeHyph${S} status: "
					if [ "$lang" != '' -a -n "$( check_package_status "$officeHyph" 'c' )" ];then
						echo "${M}available${N}"
					else
						echo "${M}no installation candidate${N}"
						officeHyph=''
					fi
					
					lang=$( echo $language | cut -d ':' -f 3 )
					officeHelp="$officePrefix-help-$lang"
					echo -n "  ${C}$officeHelp${S} status: "
					if [ "$lang" != '' -a -n "$( check_package_status "$officeHelp" 'c' )" ];then
						echo "${M}available${N}"
					else
						echo "${M}no installation candidate${N}"
						officeHelp=''
					fi
					
					lang=$( echo $language | cut -d ':' -f 4 )
					officeThesaurus="$thesaurusPrefix-$lang"
					echo -n "  ${C}$officeThesaurus${S} status: "
					if [ "$lang" != '' -a -n "$( check_package_status "$officeThesaurus" 'c' )" ];then
						echo "${M}available${N}"
					else
						echo "${M}no installation candidate${N}"
						officeThesaurus=''
					fi
					
					lang=$( echo $language | cut -d ':' -f 5 )
					officeDictionary="myspell-$lang"
					echo -n "  ${C}$officeDictionary${S} status: "
					if [ "$lang" != '' -a -n "$( check_package_status "$officeDictionary" 'c' )" ];then
						echo "${M}available${N}"
					else
						echo "${M}no installation candidate${N}"
						officeDictionary=''
					fi
				fi
				break
			else
				found='false'
			fi
		done
		break
	done

	if [ "$found" == 'true' ];then
# 		echo $LINE
		if [ "$skip" != 'true' ];then
			# officeDesktop=$( office_intgration_selector )

			echo $LINE
			echo "${S}Installing your selected language [${C}$opt${S}] components and $officeString.${N}"
			package_installer "$officePrefix-calc $officePrefix-draw $officePrefix-impress $officePrefix-java-common $officePrefix-math $officePrefix-writer python-uno dictionaries-common $officeDesktop $officeLang $officeHelp $officeThesaurus $officeDictionary $officeHyph" 'install-user'
			set_office_data # reset globals here
			echo "${S}$officeString install is completed.${N}"
		else
			echo "${S}Continuing on to main script without installing $officeString.${N}"
		fi
		eval $LOGPE
	else
		eval $LOGPE
		print_error opt
		install_libre_open_office
	fi
}
#install_libre_open_office

office_intgration_selector()
{
	local opt='' options='' complete='' officeDesktop=''
	local officePrefix='libreoffice'
	local officeString='LibreOffice'
	
	if [ "$OFFICE_AVAILABLE" == 'ooo' ];then
		officePrefix='openoffice.org'
		officeString='OpenOffice.org'
	fi
	
	echo $LINE
	echo "${S}Please select your desktop manager. This will install the correct"
	echo "$officeString desktop integration package for either kde or gnome."
	echo $LINE
	echo "${C}1 - kde${S} Installs kde integration."
	echo "${C}2 - gnome${S} Installs gnome and gtk integration. Might also work for xfce4."
	echo "${C}3 - none${S} Does not install integration package."
	echo $LINE
	echo -e $SLE
	echo $LINE

	options='kde gnome none'

	select opt in $options
	do
		case $opt in
			kde)
				officeDesktop="$officePrefix-kde"
				complete='true'
				;;
			gnome)
				officeDesktop="$officePrefix-gnome $officePrefix-gtk"
				complete='true'
				;;
			none)
				officeDesktop=''
				complete='true'
				;;
			*)
				print_error opt
				;;
		esac
		if [ "$complete" == 'true' ];then
			break
		fi
	done
	echo $officeDesktop
}

###---------------------------------------------------------------------
### package install stuff -  non free
###---------------------------------------------------------------------

java_plugin_installer()
{
	eval $LOGPS

	local installed=''
	
	echo $LINE
	echo "${S}Checking for ${C}Java Plugin${S} installation candidates...${N}"
	
	# first choice is the metapackage that is not version number based:
	if [ -n "$( check_package_status 'icedtea-plugin' 'c' )" ];then
		package_group_installer plain 'icedtea-plugin'
		installed='true'
	elif [ -n "$( check_package_status 'icedtea-8-plugin' 'c' )" ];then
		package_group_installer plain 'icedtea-8-plugin'
		installed='true'
	elif [ -n "$( check_package_status 'icedtea-7-plugin' 'c' )" ];then
		package_group_installer plain 'icedtea-7-plugin'
		installed='true'
	elif [ -n "$( check_package_status 'icedtea-6-plugin' 'c' )" ];then
		package_group_installer plain 'icedtea-6-plugin'
		installed='true'
	# legacy formats
	elif [ -n "$( check_package_status 'icedtea6-plugin' 'c' )" ];then
		package_group_installer plain 'icedtea6-plugin'
		installed='true'
	elif [ -n "$( check_package_status 'java-gcj-compat-plugin' 'c' )" ];then
		package_group_installer plain 'java-gcj-compat-plugin'
		installed='true'
	elif [ -n "$( check_package_status 'sun-java6-plugin' 'c' )" ];then
		package_group_installer plain 'sun-java6-plugin' 'update_to_nonfree_sources'
		installed='true'
	else
		echo "${M}No ${C}Java plugin${M} available in your ${C}$BITS bit $SYSTEM_BASE${M} install."
		echo "${S}Sometimes the package names change, let the ${C}$SCRIPT_NAME${S} maintainer know.${N}"
	fi
	if [ "$installed" == 'true' ];then
		echo "${S}Now checking for older versions of ${C}Java{S} to update system...${N}"
		update-alternatives --config java
	fi
	eval $LOGPE
}

# grabs the latest skype deb from the skype site and installs it
reinstall_skype()
{
	eval $LOGPS
	local SkypeFileName='' b_ia32_libs='false' package_type='32'
	# note: the skype url is a 302 to the current latest version of skype
	# local skypeDebUrl='http://www.skype.com/go/getskype-linux-beta-deb'
	# this changed and now there's a 32/64 bit auto redirect, default 32, so need to
	# make it explicit

	# dependencies: libasound2 (>> 1.0.8), libc6 (>= 2.3.2.ds1-4), libgcc1 (>= 1:3.4.1-3), libqt3-mt | libqt3c102-mt (>= 3:3.3.3.2), libstdc++5 (>= 1:3.3.4-1), libx11-6 | xlibs (>> 4.1.0), libxext6 | xlibs (>> 4.1.0)
	# libasound2 libc6 libgcc1 libstdc++5
	if [ "$BITS" == '64' -a -n "$( package_tester 'ia32-libs' )" ];then
		b_ia32_libs='true'
		package_type='64'
	fi
	local skypeDebUrl="http://www.skype.com/go/getskype-linux-deb-$package_type"
	echo $LINE
	wget -T$TIME_OUT -t2 -Nc $skypeDebUrl
	SkypeFileName=$(ls -f | grep 'skype')

	if [ -f $SkypeFileName ];then
		echo $LINE
		echo "${S}Skype deb download was successful. Beginning installation of new skype."
		echo "Removing old skype version.${N}"
		# install skype
		COLUMNS=200 dpkg -l | awk '/skype/{print $2}' | xargs -r dpkg --purge
		if [ "$BITS" == '64' -a "$b_ia32_libs" == 'false' ];then
			echo "${S}Addeing ${C}i386${S} architecture so 32 bit runs on 64 bit system...${N}"
			dpkg --add-architecture i386
			$APT_TYPE update
		fi
		echo "${S}Installing new skype.${N}"
		# package_installer 'libqtwebkit4 libstdc++5 libqt4-core libqt4-gui' 'install-user'
		dpkg -i $SkypeFileName
		rm -f $SkypeFileName
		echo "${S}Running ${C}apt-get install -f${S} to install any missing packages.${N}"
		$APT_TYPE install -f
		echo "${S}New skype install completed.${N}"
	else
		echo "${E}The skype deb file failed to download, maybe the skype server is down.${N}"
	fi
	eval $LOGPE
}

install_google_earth()
{
	eval $LOGPS
	local goog='Google Earth' uninstallPackage='' install_deb='google-earth-stable_current_i386.deb'
	local download_error=0 google_earth_package='googleearth-package'
	local b_ia32_libs='false'
	
	# we'll use 32 bit package unless it's an old install that has support for deprected ia32-libs meta
	if [ "$BITS" == '64' -a -n "$( package_tester 'ia32-libs' )" ];then
		install_deb='google-earth-stable_current_amd64.deb'
		 b_ia32_libs='true'
	fi
	local download_path=" http://dl.google.com/dl/earth/client/current/$install_deb"
	echo $LINE
	echo "${S}Starting ${C}$goog${S} installer."
	echo
	echo "Getting ${C}$goog${S} installer file and installing ${C}$goog${S} deb...${N}"
	# package_group_installer plain google-earth 'update_to_nonfree_sources'
	cd /var/cache/apt/archives
	wget -Nc $download_path || download_error=$?
	# force required to build as root
	# make-googleearth-package --force 2>>$LOG_FILE 2>&1
	# http://dl.google.com/dl/earth/client/current/google-earth-stable_current_i386.deb
	# http://dl.google.com/dl/earth/client/current/google-earth-stable_current_amd64.deb
	if [ "$download_error" -gt 0 ];then
		echo $ELINE
		echo "${E}Oh, too bad, the ${C}$install_deb${E} deb failed to download."
		echo "Please let the maintainer know, or try again in a few minutes in case it's your"
		echo "network connection that failed.${N}"
	else
		if [ -f "$install_deb" ];then
			uninstallPackage="$( package_tester '(googleearth)' )"
			echo "${S}Cleaning up previous ${C}$goog${S} materials/packages...${N}"
			if [ -n "$uninstallPackage" ];then
				package_remover "$uninstallPackage" 'purge -y' 'group'
			fi
			if [ -n "$google_earth_package" ];then
				package_remover "$google_earth_package" 'purge -y' 'group'
			fi
			if [ "$BITS" == '64' -a "$b_ia32_libs" == 'false' ];then
				echo "${S}Addeing ${C}i386${S} architecture so 32 bit runs on 64 bit system...${N}"
				dpkg --add-architecture i386
				echo "${S}Updating ${C}apt${S} now...${N}"
				$APT_TYPE update
			fi
			echo "${S}Installing ${C}$goog${S} deb...${N}"
			dpkg -i $install_deb 2>>$LOG_FILE 2>&1
			# this will pull in any needed packages the deb required
			echo "${S}Installing any missing packages for ${C}$install_deb${S}...${N}"
			apt-get install -f -y
# 			if [ "$APT_TYPE" == 'aptitude' ];then
# 				$APT_TYPE install googleearth 2>>$LOG_FILE 2>&1
# 			fi
			rm -f $install_deb
			#echo "${S}Cleaning up ${C}$goog${S} installer stuff...${N}"
			# package_remover 'googleearth-package' 'purge -y'
			echo "${S}Completed install of ${C}$goog${S}.${N}"
			echo $LINE
			echo "${S}To start ${C}$goog${S}, simply run the command from your desktop: ${C}google-earth${N}"
		else
			echo $ELINE
			echo "${E}Oh, too bad, the ${C}google earth deb${E} package failed to download, sorry about that."
			echo "${S}Check forums and other information to see if the package is changed somehow."
			echo "Unable to install googleearth, sorry.${N}"
		fi
	fi
	cd $SCRIPT_HOME
	print_hec
	eval $LOGPE
}
###---------------------------------------------------------------------
### package installers for complex stuff, utilities
###---------------------------------------------------------------------
inxi_installer()
{
	local konviPath='/usr/share/apps/konversation/scripts/'
	local konviKde4Path='/usr/share/kde4/apps/konversation/scripts/'
	local isAvailable='' inxiPath=''

	echo $LINE
	# install core depends just in case
	echo "${S}Installing ${C}inxi${S} and its dependencies/recommends..."
	echo "Checking/installing core dependency packages...${N}"
	package_group_installer 'plain' 'inxi-depends'
	echo $LINE

	# install x tools if x is installed
	if [ -n "$( check_package_status 'xserver-xorg-core' 'i' )" ];then
		echo "${S}Checking/installing graphics recommended packages...${N}"
		package_group_installer 'plain' 'inxi-xorg'
		echo $LINE
	fi
	# install dependencies
	echo "${S}Checking/installing utility recommended packages...${N}"
	package_group_installer 'plain' 'inxi-recommends'
	echo $LINE

	if [ -n "$( check_package_status 'inxi' 'c' )" ];then
		echo "${S}Installing ${C}inxi${S} package from repos now...${N}"
		package_group_installer 'plain' 'inxi'
	else
		echo "${S}Installing ${C}inxi${S} from SVN now...${N}"
		run_script_import $MOD_INXI
		echo "${S}Updating ${C}inxi${S} to force install of man page...${N}"
		$inxiPath -U
	fi
	inxiPath=$( type -p $MOD_INXI )
	if [ -n "$inxiPath" ];then
		if [ -f "$SinxiPath" -a -d $konviKde4Path ];then
			echo "${S}Creating link to ${C}${konviKde4Path}${S} now...${N}"
			ln -sf $inxiPath ${konviKde4Path}$MOD_INXI
		fi
		if [ -f "$inxiPath" -a -d $konviPath ];then
			echo "${S}Creating link to ${C}${konviPath}${S} now...${N}"
			ln -sf $inxiPath ${konviPath}$MOD_INXI
		fi
	fi
	echo "${M}Please do NOT use the ${C}-F${M} or the ${C}-v 5 (or greater)${M} options unless requested in IRC."
	echo "${S}Those are far too verbose. Please use only specific line triggers, or ${C}-b${S} or ${C}-v 1 (1-3 are reasonable)${S}"
	echo "See ${C}inxi -h${S} for the full list of supported output options.${N}"
	print_hec
}

# args: $1 - stable/sid
install_ceni()
{
	eval $LOGPS
	local appName='Ceni'

	echo $LINE
	echo "${C}$appName${S} is especially nice for wifi console networking configuration, or if you"
	echo "have any kind of complicated networking, multiple eth cards, etc."
	echo "Installing ${C}$appName${S} for you now to ${C}$SCRIPT_HOME${S}...${N}"

	# clean up manual ceni install...
	if [ -f $SCRIPT_HOME/ceni ];then
		echo "${S}Removing previous manual script install of ${C}$appName${N}"
		rm -f $SCRIPT_HOME/ceni
	fi
	package_group_installer 'plain' 'ceni-stuff'
	check_install_package 'ceni' "$1"
	echo
	echo  "${S}Congratulations. ${C}$appName${S} is now installed. To redo your networking, simply type, as root: ${C}$appName${S} (uppercase C)${N}"
	print_hec
	eval $LOGPE
}

# args: $1 - package name to test/download/install
check_install_package()
{
	eval $LOGUS
	local packageDeb="$1.deb" success=0
	if [ "$2" != '' ];then
		packageDeb="$1-$2.deb" 
	fi
	local downloadUrl="$SCRIPT_DOWNLOAD/packages/$packageDeb"
	local ua="-U s-tools/package-download.$packageDeb"
	
	echo $LINE
	# if in repo, prefer that
	if [ -n "$( check_package_status "$1" )" ];then
		package_installer "$1" 'install-always' || success=$?
	else
		echo "${S}Downloading ${C}$1${S} deb now...${N}"
		wget $ua -T$TIME_OUT -t 2 -q $downloadUrl  || success=$?
		if [ -f $packageDeb ];then
			echo "${S}Installing ${C}$1${S} deb now...${N}"
			dpkg -i $packageDeb || success=$?
		fi
		# update aptitude db with the package
		if [ "$APT_TYPE" == 'aptitude' ];then
			echo "${S}Adding ${C}$1${S} to ${C}$APT_TYPE${S} package database now...${N}"
			$APT_TYPE install $1 2>>$LOG_FILE 2>&1
		fi
		rm -f $packageDeb
	fi
	if [ "$success" -gt 0 ];then
		log_function_data "Error: $packageDeb download/install failed, error code: $success"
		echo "${E}Install of ${C}$1${E} failed, sorry.${N}"
	else
		echo "${S}Install of ${C}$1${S} was successful.${N}"
	fi
	#print_hec
	eval $LOGUE
}

h2_faves()
{
	eval $LOGPS
	local removeItems='splashy'
	local mozGroup="${C}iceweasel${S} and ${C}icedove${S}"

	if [ "$SERVER_CLIENT" == 'server' ];then
		mozGroup="${C}iceweasel${S}"
	fi

	echo $LINE
	echo "${S}Starting the h2 favorites install process now...${N}"
	h2_package_group_remover "$removeItems"
	h2_package_group_installer 'console-tools'
	h2_package_group_installer 'console-browsers'
	h2_package_group_installer 'system-utilities'
	h2_package_group_installer 'inxi'
	h2_package_group_installer 'rsync-group'
	echo "${S}mozilla-group is $mozGroup...${N}"
	h2_package_group_installer 'mozilla-group'
	h2_package_group_installer 'kde-extras'
	echo
	echo $LINE
	echo "${S}Ok, all done with h2 favorite installs.${N}"
	print_hec
	eval $LOGPE
}

# args: $1 - packages to remove
h2_package_group_remover()
{
	eval $LOGUS
	local opt='' options='' repeat='' removeItems=$1 package=''

	for package in $removeItems
	do
		if [ -n "$( package_tester $package )" ];then
			echo
			echo "${S}Removing ${C}$package${S} now... "
			echo $LINE
			echo "${C}1 - ${S} Remove ${C}$package${S}"
			echo "${C}2 - ${S} Keep ${C}$package${S}"
			echo $LINE
			echo -e $SLE
			echo $LINE
			options="yes-remove-$package keep-$package"
			select opt in $options
			do
				log_function_data "opt selected: $opt"
				case $opt in
					yes-remove-$package)
						package_remover "$package" 'purge'
						;;
					keep-$package)
						echo "${S}Ok, not removing $package...${N}"
						;;
					*)
						print_error opt
						repeat='true'
						;;
				esac
				break
			done

			eval $LOGUE
			if [ "$repeat" == 'true' ];then
				h2_package_group_remover "$1"
			fi
		fi
	done

	eval $LOGUE
}

# args: $1 packages to be installed
h2_package_group_installer()
{
	eval $LOGUS
	local opt='' options='' repeat=''

	echo $LINE
	echo -e $SLE
	echo $LINE
	echo "${C}1${S} - Install ${C}$1"
	echo "${C}2${S} - Don't install ${C}$1"
	echo $LINE
	options="yes-install-$1 skip-$1"
	select opt in $options
	do
		log_function_data "opt selected: $opt"
		case $opt in
			yes-install-$1)
				case $1 in
					inxi)
						inxi_installer
						;;
					*)
						package_group_installer 'plain' "$1"
						;;
				esac
				;;
			skip-$1)
				echo "${S}Ok, skipping that group of packages...${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done

	eval $LOGUE
	if [ "$repeat" == 'true' ];then
		h2_package_group_installer "$1"
	fi
}

# swap captive for ntfs-3g ntfs driver
install_ntfs_3g()
{
	eval $LOGPS
	echo $LINE
	echo "${S}For more information on how to setup ntfs-3g, please read ${C}/usr/share/doc/ntfs-3g/README.gz${S}"
	# echo "or use the ${C}aptosid-irc${S} factoid ${C}!ntfs-3g${S}."
	echo "Here is a sample new line in your ${C}/etc/fstab${S} to give you an idea:"
	echo "${C}/dev/hda1       /media/hda1     ntfs-3g silent,umask=0,no_def_opts,allow_other 0 0"
	print_hec
	echo "${S}Changing ${C}Captive${S} to ${C}ntfs-3g${S} now."
	echo "${S}Removing all ${C}captive${S} components....${N}"
	package_remover 'captive captive-lufs gnome-vfs-httpcaptive captive  captive-install ntfsprogs-gnomevfs' 'purge'
	package_installer 'ntfs-3g' 'install-user'
	echo "${S}Your system will now use ${C}ntfs-3g${S} to read your ntfs files.${N}"
	eval $LOGPE
}

install_kpowersave()
{
	eval $LOGPS
	local response=''

	echo $LINE
	echo "${S}Installing kpowersave and related components now."
	echo "This uses ${C}unfreeze-rc.d${S} and ${C}freeze-rc.d${S} to update the services.${N}"
	echo $LINE
	unfreeze-rc.d
	package_remover 'apmd powernowd' 'purge'
	package_installer 'kpowersave' 'install-user'
	freeze-rc.d

	echo $LINE
	echo "${S}Please remember, you will need to add your username to the ${C}powerdev${S} group"
	echo "before this will take affect."
	echo "You can do that like this, as root: ${C}adduser <your-normal-login-name> powerdev"
	echo
	echo "${C}Kpowersave${S} will not run until you rebooot."
	echo -e "${Q}Would you like to reboot now?$YNE"
	echo $LINE
	read response

	case $response in
		y)
			echo $LINE
			echo "${S}Rebooting now...${N}"
			handle_shutdowns 'reboot'
			;;
		n)
			echo $LINE
			echo "${S}Ok, but remember, you'll need to reboot before the new kpowersave stuff becomes active.${N}"
			;;
		*)
			print_error yn
			install_kpowersave
			;;
	esac
	eval $LOGPE
}

swiftfox_installer()
{
	eval $LOGPS
	local opt='' options='' swiftOpt='' swiftPackage='' found='' skip=''
	local LC_ALL= LC_CTYPE= LC_MESSAGES= LANG= cpuType=$( grep -i -m 1 'model name' /proc/cpuinfo | cut -d ':' -f 2  )
	# current swiftfox packages
	# http://getswiftfox.com/builds/debian/packages
	# note, the following were dropped:
	# swiftfox-athlon-xp
	# swiftfox-pentium-m
	# swiftfox-pentium3
	# swiftfox-pentium3m
	# swiftfox-pentium4
	
	local swiftfoxChoices="
	swiftfox-i686:(Athlon-Thunderbird/xp-or-Pentium-2/3/m/4)
	swiftfox-athlon64-32bit:(AMD-64-users-on-a-32bit-OS)
	swiftfox-prescott:(Intel-Core-duo/solo)
	return-to-menu
	"

	# no point in offering 32 bit package here for 64 bit users, and vica versa
	if [ "$BITS" == '64' ];then
		swiftfoxChoices="
		swiftfox-athlon64:(AMD-64-users-on-a-64bit-OS)
		swiftfox-prescott:(Intel-Core-duo/solo)
		return-to-menu
		"
	fi

	local rtmmNu=$( wc -w <<< $swiftfoxChoices )
	local swiftNu=$(( $rtmmNu -1 ))

	echo $MLINE
	echo "${M}Swiftfox Installer"
	echo $MLINE
	echo "${S}You can pick a swiftfox version for your system's cpu:"
	echo "${C}$cpuType ${S}(running a ${C}$BITS bit${S} operating system)"
	echo "${S}Once you make your selection, ${C}$SCRIPT_NAME${S} will install that swiftfox version."
	echo
	echo "${M}Keep in mind, it's risky running two versions of Firefox, like Iceweasel and Swiftfox.${S}"
	echo "I recommend using only one Mozilla based browser, but I tend to be careful."
	echo
	echo "If needed, ${C}$SCRIPT_NAME${S} will add the required swiftfox sources for apt before installing."
	echo $LINE
	echo "${C}1-$swiftNu - ${S}Select which swiftfox version you want to install."
	echo
	echo "${C}$rtmmNu - return-to-menu${S} Return to utility installer."

	echo $LINE
	echo -e $SLE
	echo $LINE

	options=$swiftfoxChoices

	select opt in $options
	do
		for swiftOpt in $swiftfoxChoices
		do
			if [ "$opt" == "$swiftOpt" ];then
				found='true'
				if [ "$swiftOpt" == 'return-to-menu' ];then
					skip='true'
				else
					swiftPackage="$( cut -d ':' -f 1 <<< $swiftOpt )"
				fi
				break
			else
				found='false'
			fi
		done
		break
	done

	if [ "$found" == 'true' ];then
		if [ "$skip" != 'true' ];then
			update_sources swiftfox
			package_installer "$swiftPackage libxp6" 'install-user' '--allow-unauthenticated'
			run_script_import $LIB_MISC_TWEAKS
			swiftfox_link_tweak
			# echo installing $swiftPackage now...
		else
			echo $LINE
			echo "${S}Returning to main script now...${N}"
		fi
		eval $LOGPE
	else
		eval $LOGPE
		print_error opt
		swiftfox_installer
	fi
}

###---------------------------------------------------------------------
### package install stuff -  servers
###---------------------------------------------------------------------

server_group_selector()
{
	eval $LOGPS
	local repeat=''

	echo $MLINE
	echo "${M} Server Installer"
	echo $MLINE

	echo "${S}The following basic package groups are offered. Please check out each sub-category"
	echo "to see if there's anything you need. If they are missing something, please let"
	echo "the ${C}$SCRIPT_NAME${S} maintainer know and he'll add it."
	echo $LINE
	echo "${C}1 - apache-mysql-php${S} - A range of web servers: ${C}Apache2${S}, ${C}PHP${S}, ${C}MySql${S};"
	echo "    Also extra language and program modules."
	echo "${C}2 - nfs${S} - Basic ${C}*nix${S} type networking, nice and simple."
	echo "${C}3 - samba${S} - ${C}*nix${S} Windows type networking server and tools."
	echo "${C}4 - back-to-menu${S} - Return to main menu."
	echo $LINE
	echo -e $SLE
	echo $LINE
	options="apache-mysql-php nfs samba back-to-menu"
	select opt in $options
	do
		log_function_data "opt selected: $opt"
		case $opt in
			apache-mysql-php)
				apache_package_installer
				repeat='true'
				;;
			nfs)
				nfs_package_installer
				repeat='true'
				;;
			samba)
				samba_package_installer
				repeat='true'
				;;
			back-to-menu)
				echo "${S}Ok, enough with the servers stuff, back to main menu...${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done

	eval $LOGPE
	if [ "$repeat" == 'true' ];then
		server_group_selector
	fi
}

nfs_package_installer()
{
	eval $LOGPS
	local repeat=''

	echo $MLINE
	echo "${M}NFS Server and Client"
	echo $MLINE

	echo "${S}The following servers, and client apps, are available:${N}"
	echo $LINE
	echo "${C}1 - nfs-server${S} - The entire ${C}NFS package${S}."
	echo "${C}2 - nfs-client${S} - Just the client components."
	echo "${C}3 - back-to-menu${S} - Return to main menu."
	echo $LINE
	echo -e $SLE
	echo $LINE
	options="nfs-server nfs-client back-to-menu"
	select opt in $options
	do
		log_function_data "opt selected: $opt"
		case $opt in
			nfs-server)
				package_group_installer 'plain' 'nfs-kernel-server nfs-common portmap'
				repeat='true'
				;;
			nfs-client)
				package_group_installer 'plain' 'nfs-common portmap'
				repeat='true'
				;;
			back-to-menu)
				echo "${S}Ok, returning to main menu...${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done

	eval $LOGPE
	if [ "$repeat" == 'true' ];then
		nfs_package_installer
	fi
}

apache_package_installer()
{
	eval $LOGPS
	local repeat=''

	echo $MLINE
	echo "${M}Apache, PHP, and MySql Installation"
	echo $MLINE

	echo "${S}The following servers, client apps, and tools, are available. These, when all selected, "
	echo "will result in a fairly complete and modern ${C}Apache2${S} web server installation."
	echo
	echo "${S}After you are done, type into any browser: ${C}localhost${S}"
	echo "and you should see the defualt Apache warning page.${N}"
	echo $LINE
	echo "${M}::  Apache  ::"
	echo "${C}1 - apache2-full${S} - Installs ${C}Apache${S}, ${C}MySql${S}, and ${C}PHP${S}, in the proper order."
	echo "${C}2 - apache2-server${S} - Installs ${C}apache2-mpm-prefork${S} server and ${C}apache2-utils${S}"
# 	echo "${C}3 - apache2-configuration${S} - Installs ${C}rapache${S} a graphical user tool for configuring ${C}Apache2${S}"
# 	echo "    It allows easy creation of virtual name hosts and activating modules all without any"
# 	echo "    knowledge of configuration files (${M}I have NOT tested this tool${S})."

	echo "${M}::  MySql  ::"
	echo "${C}3 - mysql5-server${S} - Main Database server for ${C}Apache2${S} installs. Install first if you are adding Apache2."
	echo "${C}4 - mysql5-client${S} - Includes the client binaries and the additional tools
 innotop, mysqlreport"
	echo "${C}5 - mysql-top${S} - Installs ${C}mtop${S} and ${C}mytop${S} command line ${C}mysql${S} monitoring tools (like ${C}top${S})."

	echo "${M}::  PHP / Python / Perl / Ruby ::"
	echo "${C}6 - apache2-mod-php5${S} - This is the main PHP5 Apache2 module."
	echo "${C}7 - php5-modules${S} - Installs useful ${C}gd${S} and ${C}curl${S} modules for Apache2/PHP."
	echo "${C}8 - php5-mysql${S} - Installs the MySql database PHP module."
	echo "${C}9 - php5-postgre${S} - Installs the Postgre database PHP module."
	echo "${C}10 - apache2-mod-perl${S} - Installs the Apache2 Perl module."
	echo "${C}11 - apache2-mod-python${S} - Installs the Apache2 Python module."
	echo "${C}12 - apache2-mod-ruby${S} - Installs the Apache2 Ruby module."
	echo
	echo "${C}13 - back-to-menu${S} - Return to main menu."
	echo $LINE
	echo -e $SLE
	echo $LINE
	options="apache2-full apache2-server mysql5-server mysql5-client mysql-top apache2-mod-php5 php5-modules php5-mysql php5-postgre apache2-mod-perl  apache2-mod-python apache2-mod-ruby back-to-menu"
	select opt in $options
	do
		log_function_data "opt selected: $opt"
		case $opt in
			apache2-configuration)
				package_group_installer 'plain' 'apache2-configuration'
				repeat='true'
				;;
			apache2-full)
				package_group_installer 'plain' 'mysql5-server'
				package_group_installer 'plain' 'apache2-server'
				package_group_installer 'plain' 'apache2-mod-php5'
				package_group_installer 'plain' 'php5-mysql'
				echo "${S}Reconfiguring ${C}php5-mysql${S} now...${N}"
				dpkg-reconfigure php5-mysql
				repeat='true'
				;;
			apache2-server)
				package_group_installer 'plain' 'apache2-server'
				repeat='true'
				;;
			apache2-mod-perl)
				package_group_installer 'plain' 'apache2-mod-perl'
				repeat='true'
				;;
			apache2-mod-php5)
				package_group_installer 'plain' 'apache2-mod-php5'
				repeat='true'
				;;
			apache2-mod-python)
				package_group_installer 'plain' 'apache2-mod-python'
				repeat='true'
				;;
			apache2-mod-ruby)
				package_group_installer 'plain' 'apache2-mod-ruby'
				repeat='true'
				;;
			mysql5-client)
				package_group_installer 'plain' 'mysql5-client'
				repeat='true'
				;;
			mysql5-server)
				package_group_installer 'plain' 'mysql5-server'
				repeat='true'
				;;
			mysql-top)
				package_group_installer 'plain' 'mysql-top'
				repeat='true'
				;;
			php5-modules)
				package_group_installer 'plain' 'php5-modules'
				repeat='true'
				;;
			php5-mysql)
				package_group_installer 'plain' 'php5-mysql'
				repeat='true'
				;;
			php5-postgre)
				package_group_installer 'plain' 'php5-postgre'
				repeat='true'
				;;
			back-to-menu)
				echo "${S}Ok, returning to main menu...${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done

	eval $LOGPE
	if [ "$repeat" == 'true' ];then
		apache_package_installer
	fi
}

samba_package_installer()
{
	eval $LOGPS
	local repeat=''

	echo $MLINE
	echo "${M}Samba Server, Clients, and Tools"
	echo $MLINE
	echo "${S}The following servers, client apps, and tools, are available:${N}"
	echo $LINE
	echo "${M}::  Samba Server ::"
	echo "${C}1 - samba-server${S} - the main ${C}Samba${S} server. Does not include ${C}smbclient${S},"
	echo "    ${C}smbfs${S}, or ${C}winbind${S}."
	# note: swat appears to have been removed from debian due to project not being maintained
	#  echo "${C}2 - swat${S} - Web administration tool for ${C}Samba${S} server."
	echo "${M}::  Samba Clients ::"
	echo "${C}2 - smb-client${S} - These ${C}Samba ${S}client packages both contain the command"
	echo "    line utilities${C}smbclient${S}, ${C}smbtar${S}, and ${C}smbspool${S}, as well as ${C}smbfs${S}."
	echo "${C}3 - smb4k${S} - ${C}smb4k${S} is the kde version of ${C}smb-client${S}."
 	echo "${C}4 - komba2${S} - A kde GUI machine and share browser for the SMB protocol."
	echo "${M}::  Samba Tools ::"
	echo "${C}5 - winbind${S} - Provides winbind. Can be used to resolve user and group information"
	echo "    from a Windows NT server."
	echo "${C}6 - fuse-smb${S} - ${C}smb${S} filesystem client + ${C}fuse-utils${S}. Requires ${C}fuse kernel module${S}."
	echo "${C}7 - samba-docs${S} - Documenation for ${C}Samba${S}, also in ${C}pdf${S} format."

	echo "${C}8 - back-to-menu${S} - Return to main menu."
	echo $LINE
	echo -e $SLE
	echo $LINE
	options="samba-server samba-client smb4k komba2 winbind fuse-smb samba-docs back-to-menu"
	select opt in $options
	do
		log_function_data "opt selected: $opt"
		case $opt in
			samba-server)
				package_group_installer 'plain' 'samba'
				repeat='true'
				;;
			samba-client)
				package_group_installer 'plain' 'smbclient samba-common smbfs'
				repeat='true'
				;;
			smb4k)
				package_group_installer 'plain' 'smb4k samba-common smbfs'
				repeat='true'
				;;
			swat)
				package_group_installer 'plain' 'swat'
				repeat='true'
				;;
			komba2)
				package_group_installer 'plain' 'komba2'
				repeat='true'
				;;
			fuse-smb)
				package_group_installer 'plain' 'fusesmb fuse-utils'
				repeat='true'
				;;
			samba-docs)
				package_group_installer 'plain' 'samba-doc samba-doc-pdf'
				repeat='true'
				;;
			winbind)
				package_group_installer 'plain' 'winbind'
				repeat='true'
				;;
			back-to-menu)
				echo "${S}Ok, returning to main menu...${N}"
				;;
			*)
				print_error opt
				repeat='true'
				;;
		esac
		break
	done

	eval $LOGPE
	if [ "$repeat" == 'true' ];then
		samba_package_installer
	fi
}

###**EOF**###